/**
 * @file inforevise/Home.js
 *  信息修改
 * @author
 */

import React, {Component,PropTypes} from 'react';
import {connect} from 'dva';
import {routerRedux,withRouter } from 'dva/router';
import { Form, Input,Card, Button, Row, Col } from 'antd';
import Tabtitle from '../../../components/common/TabTitle';

import styles from './home.less';

const FORM_ITEM_LAYOUT = {
	labelCol: {
		xl:{
			span:8
		},
		lg:{
			span:8
		},
		xs: {
			span: 4,
		},
		sm: {
			span: 4,
		},
	},
	wrapperCol: {
		xl:{
			span:8
		},
		lg:{
			span:8
		},
		sm: {
			span: 10,
		},
		xs: {
			span: 8,
		},
	},
};
const FormItem = Form.Item;
const Inforevise = ({
	dispatch,
	infoedit,
	location,
	form: { 
			getFieldDecorator,
			validateFields,
			getFieldsValue },
}) => {
	function handleSubmit(e) {
		e.preventDefault();
		validateFields((err, fieldsValue) => {
			console.log("fieldsValue>>>>",fieldsValue)
			if (err) {
				return;
			}
			dispatch({
				type: 'infoedit/saveInfo',
				payload: {
					...fieldsValue,
				}
			})
		})
	}
	if(infoedit.status){
		const data = infoedit.userinfo;
		return (
			<div>
				<Tabtitle value={'信息修改'}/>
				<div className="page-info-home content-inner" style={{ background: '#ECECEC', padding: '30px' }}>
					<Card >
						<Form onSubmit={handleSubmit} className={styles.forminfo}>
							<FormItem
								{...FORM_ITEM_LAYOUT}
								label="用户名"
							>
								{getFieldDecorator(
									'username',
									{
										rules: [
											
										],
										initialValue: data.username,
									},
								)(
									<Input disabled />,
								)}
							</FormItem>
							<FormItem
								{...FORM_ITEM_LAYOUT}
								label="姓名"
							>
								{getFieldDecorator(
									'name',
									{
										rules: [
											
										],
										initialValue: data.name,
									},
								)(
									<Input disabled/>,
									)}
							</FormItem>

							<FormItem
								{...FORM_ITEM_LAYOUT}
								label="联系方式"
								hasFeedback
							>
								{getFieldDecorator(
									'mobile',
									{
										rules: [
											{ whitespace: true, pattern: /^((0\d{2,3}-\d{7,8})|(1[0-9]\d{9}))$/, message: '格式错误!' },
											{ required: true, whitespace: true, message: '请输入联系方式!' },
										],
									 initialValue: data.mobile,
									},
								)(
									<Input />,
								)}
							</FormItem>
							<FormItem
								{...FORM_ITEM_LAYOUT}
								label="邮箱"
								hasFeedback
							>
								{getFieldDecorator(
									'email',
									{
										rules: [
											{ whitespace: true, pattern: /^(\w)+(\.\w+)*@(\w)+((\.\w{2,3}){1,3})$/ 	, message: '请输入正确邮箱地址!' },
											{ required: true, whitespace: true, message: '请输入邮箱地址!' },
										],
										initialValue: data.email,
									},
								)(
									<Input />,
								)}
							</FormItem>

							<FormItem
								{...FORM_ITEM_LAYOUT}
								label="机构"
							>
								{getFieldDecorator(
									'orgName',
									{
										rules: [
											
										],
								 	initialValue: data.orgName,
									})(
										<Input disabled  />,
								)}
							</FormItem>
							<FormItem
							 {...FORM_ITEM_LAYOUT}
							 label="用户职能"
							>
								{getFieldDecorator('authorityName', {
								 initialValue: data.authorityName,
									rules: [
											
										],
								})(
									<Input disabled  />,
									)}
							</FormItem>
							<FormItem
								wrapperCol={{
									xl: { span: 13, offset: 8 },
									lg: { span: 13, offset: 8 },
									xs: { span: 8, offset: 4 },
									sm: { span: 6, offset: 7 },
								}}
							>
								<Row >
									<Col span={6} push={6}>
										<Button type="primary" htmlType="submit" size="large" to="/"  >提交</Button>
									</Col>
									
								</Row>
							</FormItem>
						</Form>
					</Card>
				</div>
			</div>
		)
	}else{
		return null;
	}
	
}
Inforevise.propTypes = {
	// form: PropTypes.object.isRequired,
}

export default connect(({infoedit})=>({infoedit}))(Form.create()(Inforevise))